﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class FinancialController : ControllerBase
    {
        private readonly DZJDBcontext db;

        public FinancialController(DZJDBcontext context)
        {
            db = context;
        }

        /// <summary>
        /// 查找
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<EM_Financial> GetAll()
        {
            return db.EM_Financial.ToList();
        }

        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="Financial"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Add(EM_Financial Financial)
        {
            db.EM_Financial.Add(Financial);
            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }


        /// <summary>
        /// 改
        /// </summary>
        /// <param name="Financial"></param>
        /// <returns></returns>
        [HttpPut]
        public bool Update(EM_Financial Financial)
        {
            db.EM_Financial.Update(Financial);
            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool Delete(Guid Id)
        {
            EM_Financial? Financial = new EM_Financial();
            Financial = db.EM_Financial.Where(s => s.ID == Id).FirstOrDefault();
            if (Financial != null)
                db.EM_Financial.Remove(Financial);
            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }
    }
}
